	public static int optionFlags = 0;
	public static Menu optionsMenu;	
	public static long messageShowStart = 0;
	public static int messageId = OPTIONS.MESSAGE_ID_IDLE;
	
	public boolean isOptionEnabled(int optionId)
	{
		return ((optionFlags & OPTIONS.FLAGS[optionId]) != 0);
	}
	
	public void enableOption(int optionId)
	{
		optionFlags |= OPTIONS.FLAGS[optionId];
	}
	
	public void disableOption(int optionId)
	{
		optionFlags &= (~OPTIONS.FLAGS[optionId]);
	}
	
	public int getOptionValue(int optionId)
	{
		return ((optionFlags >> optionId) & 0x1F);
	}
	
	public void showMessage(int mId, int messageType)
	{		
		switch(messageType)
		{
			case OPTIONS.MESSAGE_TYPE_CONFIRM:
			{
				cGame_g.setFont(DGraph.FONT_SMALL);
				cGame_g.setColor(MENUS.MAIN_MENU_BACKGROUND_COLOR);
				cGame_g.setFontColor(MENUS.MAIN_MENU_HIGHLIGHT_COLOR);
				String playerEnd = tegPlayers[((cPlayer.turn - 1 < 0)? (rules[RULES.MATCH_PLAYERS] - 1) : (cPlayer.turn - 1))].name;
				String playerNext = tegPlayers[cPlayer.turn].name;
				String text = ((mId==OPTIONS.MESSAGE_ID_END_TURN)? playerEnd : "") + TEXT.INGAME_MESSAGE[mId] + ((mId==OPTIONS.MESSAGE_ID_END_TURN)? playerNext : "");
				int width = SCREEN_WIDTH / 3 * 2;
				int height = cGame_g.getStringHeight(text, INGAME.PLAYER_INFO_W + cGame_g.getFontWidth() * 2) + cGame_g.getFontHeight() * 2;
				cGame_g.drawAlphaRect(INGAME.VIEWPORT_X, INGAME.VIEWPORT_Y, INGAME.VIEWPORT_W, INGAME.VIEWPORT_H, MENUS.MAIN_MENU_ALPHA_LEVEL);
				cGame_g.drawAlphaRect(SCREEN_WIDTH / 2 - width / 2, SCREEN_HEIGHT / 2 - height / 2, width, height, MENUS.MAIN_MENU_ALPHA_LEVEL);
				cGame_g.setColor(MENUS.MAIN_MENU_FOREGROUND_COLOR);
				cGame_g.drawRect(SCREEN_WIDTH / 2 - width / 2, SCREEN_HEIGHT / 2 - height / 2, width, height);
				cGame_g.drawString(text, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 - height / 2 + cGame_g.getFontHeight() + cGame_g.getFontHeight() / 3, width - cGame_g.getFontWidth() * 2, DSmallFont.TOP | DSmallFont.HCENTER);
				cGame_g.setFont(DGraph.FONT_BIG);
				cGame_g.setFontColor(MENUS.MAIN_MENU_FOREGROUND_COLOR);
				drawSoftKeys(SOFTKEYS.STR_OK, SOFTKEYS.STR_NONE);
				
				if(isKeyPressed(KEYS.KEY_LSK))
				{
					messageId = OPTIONS.MESSAGE_ID_IDLE;
					messageShowStart = 0;
				}
				clearKeys();
			}
			break;
			
			case OPTIONS.MESSAGE_TYPE_INFO:
			{	
				if(System.currentTimeMillis() - messageShowStart > OPTIONS.MESSAGE_SHOW_TIME[mId])
				{
					messageShowStart = 0;
				}
			
				cGame_g.setFont(DGraph.FONT_SMALL);
				int height = cGame_g.getStringHeight(TEXT.INGAME_MESSAGE[mId], INGAME.PLAYER_INFO_W + cGame_g.getFontWidth() * 2) + (cGame_g.getFontHeight() / 3) * 2;
				cGame_g.setColor(MENUS.MAIN_MENU_BACKGROUND_COLOR);
				cGame_g.setFontColor(MENUS.MAIN_MENU_FOREGROUND_COLOR);
				cGame_g.drawAlphaRect(INGAME.PLAYER_INFO_VIEWPORT_OFFSET, INGAME.VIEWPORT_Y + INGAME.PLAYER_INFO_VIEWPORT_OFFSET, INGAME.PLAYER_INFO_W, height, MENUS.MAIN_MENU_ALPHA_LEVEL);
				cGame_g.setColor(MENUS.MAIN_MENU_FOREGROUND_COLOR);
				cGame_g.drawRect(INGAME.PLAYER_INFO_VIEWPORT_OFFSET, INGAME.VIEWPORT_Y + INGAME.PLAYER_INFO_VIEWPORT_OFFSET, INGAME.PLAYER_INFO_W, height);
				cGame_g.drawString(TEXT.INGAME_MESSAGE[mId], INGAME.PLAYER_INFO_VIEWPORT_OFFSET * 2 - 1, INGAME.VIEWPORT_Y + INGAME.PLAYER_INFO_VIEWPORT_OFFSET + cGame_g.getFontHeight() / 2, INGAME.PLAYER_INFO_W + cGame_g.getFontWidth() * 2, DSmallFont.TOP | DSmallFont.LEFT);
				cGame_g.setFont(DGraph.FONT_BIG);
			}
			break;
		}
	}
	
	public void UpdateOptions()
	{
		cGame_g.setFont(DGraph.FONT_SMALL);
		if(optionsMenu == null)
		{
			optionsMenu = new Menu(SCREEN_WIDTH, SCREEN_HEIGHT, MENUS.MAIN_MENU_BACKGROUND_COLOR, MENUS.MAIN_MENU_FOREGROUND_COLOR, MENUS.MAIN_MENU_HIGHLIGHT_COLOR, 0, TEXT.OPTIONS_ENTRIES, cGame_g);
			optionsMenu.setOnOffEntry(OPTIONS.SOUND, isOptionEnabled(OPTIONS.SOUND));
			optionsMenu.setOnOffEntry(OPTIONS.COUNTRY_NAME_ON_TOP, isOptionEnabled(OPTIONS.COUNTRY_NAME_ON_TOP));
			optionsMenu.setOnOffEntry(OPTIONS.AUTOSAVE, isOptionEnabled(OPTIONS.AUTOSAVE));
			optionsMenu.setValueEntry(OPTIONS.MAP_SCROLLING_SPEED, INGAME.MIN_SCROLLING_SPEED, INGAME.MAX_SCROLLING_SPEED);
			optionsMenu.setEntryValue(OPTIONS.MAP_SCROLLING_SPEED, ((getOptionValue(OPTIONS.MAP_SCROLLING_SPEED) < INGAME.MIN_SCROLLING_SPEED)? INGAME.MIN_SCROLLING_SPEED : getOptionValue(OPTIONS.MAP_SCROLLING_SPEED)));
			optionsMenu.width += 10;
			optionsMenu.x -= 5;
		}
		
		optionsMenu.handleInput(keyflags);
		optionsMenu.draw(Menu.RECT_TYPE_PLAIN);
		
		cGame_g.setFontColor(SOFTKEYS.COLOR);
		cGame_g.setFont(DGraph.FONT_BIG);
		drawSoftKeys(SOFTKEYS.STR_NONE, SOFTKEYS.STR_BACK);
		
		if(isKeyPressed(KEYS.KEY_RSK))
		{
			for(int i = 0; i < TEXT.OPTIONS_ENTRIES.length; i++)
			{
				if(optionsMenu.getEntryType(i) == Menu.TYPE_ON_OFF)
				{
					boolean optionState = optionsMenu.getOnOffState(i);
					if(optionState)
					{
						enableOption(i);
					}
					else
					{
						disableOption(i);
					}
				}
				else if(optionsMenu.getEntryType(i) == Menu.TYPE_VALUE)
				{
					optionFlags &= (~(0x1F<<(i + 5 * (i - OPTIONS.MAP_SCROLLING_SPEED))));
					optionFlags |= (optionsMenu.getEntryState(i) << (i + 5 * (i - OPTIONS.MAP_SCROLLING_SPEED)));
				}
			}
			SetState(prev_game_state);
			clearKeys();
		}
	}